package com.vodone.v1pin.productlist.service
{
	import com.vodone.v1pin.ServiceProvider;
	import com.vodone.v1pin.core.service.HttpJsonDelegate;
	import com.vodone.v1pin.productlist.vo.ActivityVO;
	import com.vodone.v1pin.productlist.vo.BrandInfoVO;
	import com.vodone.v1pin.productlist.vo.ProductItemVO;
	import com.vodone.v1pin.productlist.vo.ProductListVO;
	import com.vodone.v1pin.productlist.vo.QueryItemVO;
	
	import flash.utils.setTimeout;
	
	import mx.collections.ArrayCollection;
	import mx.rpc.http.mxml.HTTPService;

	public class ProductListDelegate
	{
		CONFIG::isReal
		public static function getProductList( resultHandler:Function ,  
											   currentPage:int , pageSize:int, 
											   catetory:String = "" ,
											   keyword:String = "" , sex:String = "" , brand:String = "" , 
											   color:String = "" , price:String = "" , size:String = "" ,
											   property:String = "" , sort:int = 1 , showSellout:Boolean = false,
											   recommendId:String = "" , type:int = 0 , faultHandler:Function = null ):void
		{
			var service:HTTPService = ServiceProvider.getInstance().getProductListService;
			var params:Object = {
				currentPage : currentPage,
				pageSize: pageSize,
				category : catetory,
				keyword : keyword,
				sex : sex,
				brand : brand,
				color : color,
				price : price,
				size : size,
				property : property,
				sort : sort,
				showSellout : showSellout,
				recommendId : recommendId,
				type : type 
			}
			
			var delegate:HttpJsonDelegate = new HttpJsonDelegate( service );
			delegate.send( params , resultHandler , faultHandler );
		}
		
		CONFIG::isMock
		public static function getProductList( resultHandler:Function ,  
											   currentPage:int , pageSize:int, 
											   catetory:String = "" ,
											   keyword:String = "" , sex:String = "" , brand:String = "" , 
											   color:String = "" , price:String = "" , size:String = "" ,
											   property:String = "" , sort:int = 1 , showSellout:Boolean = false,
											   recommendId:String = "" ,  type:int = 0 , faultHandler:Function = null ):void
		{
			var picList:Array = [
				"http://i0.ihaveu.net.cn/image/auction/product/004/010/631/major_pic/d60f0391.jpg.thumb145.jpg",
				"http://i2.ihaveu.net.cn/image/auction/product/000/400/011/major_pic/f1ccf240.jpg.thumb145.jpg",
				"http://i1.ihaveu.net.cn/image/auction/product/000/400/441/major_pic/14d9576b.jpg.thumb145.jpg",
				"http://i0.ihaveu.net.cn/image/auction/product/004/010/631/major_pic/d60f0391.jpg.thumb145.jpg",
				"http://i3.ihaveu.net.cn/image/auction/product/004/010/853/major_pic/3124c6bd.jpg.thumb145.jpg",
				"http://i3.ihaveu.net.cn/image/auction/product/003/999/324/major_pic/76a13acb.jpg.thumb145.jpg",
			]
			var listVO:ProductListVO = new ProductListVO();
			listVO.currentPage = currentPage;
			listVO.pageSize = pageSize;
			listVO.totalCount = 200;
			listVO.recommendCount = 2;
			listVO.activity = new ActivityVO({pic:"http://i2.ihaveu.net.cn/image/auction/product/000/400/011/major_pic/f1ccf240.jpg.thumb145.jpg",size:1,url:"http://www.baidu.com"});
			listVO.colorList = new ArrayCollection([
				new QueryItemVO({label:"绿色",extend:"0x00ff00",id:"1"}),
				new QueryItemVO({label:"红色",extend:"0xff0000",id:"2"}),
			]);
			listVO.brandList = new ArrayCollection([
				new QueryItemVO({label:"石英",extend:"0x00ff00",id:"1"}),
				new QueryItemVO({label:"自动机械",extend:"0x00ff00",id:"1"}),
				new QueryItemVO({label:"电子",extend:"0x00ff00",id:"1"}),
				new QueryItemVO({label:"人工动能",extend:"0x00ff00",id:"1"}),
			]);
			listVO.priceList =  new ArrayCollection([
				new QueryItemVO({label:"100~800",extend:"0x00ff00",id:"1"}),
				new QueryItemVO({label:"800~1100",extend:"0x00ff00",id:"1"}),
				new QueryItemVO({label:"1100~1600",extend:"0x00ff00",id:"1"}),
				new QueryItemVO({label:"1600~2300",extend:"0x00ff00",id:"1"}),
				new QueryItemVO({label:"2300~3300",extend:"0x00ff00",id:"1"}),
			]);
			listVO.propertyList = new ArrayCollection([
				new QueryItemVO({label:"100~800",extend:"0x00ff00",id:"1"}),
				new QueryItemVO({label:"100~800",extend:"0x00ff00",id:"1"}),
				new QueryItemVO({label:"100~800",extend:"0x00ff00",id:"1"}),
				new QueryItemVO({label:"100~800",extend:"0x00ff00",id:"1"}),
			]);
			listVO.sexList = new ArrayCollection([
				new QueryItemVO({label:"男",extend:"0x00ff00",id:"1"}),
				new QueryItemVO({label:"女",extend:"0x00ff00",id:"1"}),
				new QueryItemVO({label:"中性",extend:"0x00ff00",id:"1"}),
				new QueryItemVO({label:"儿童",extend:"0x00ff00",id:"1"}),
			]);
			listVO.sizeList = new ArrayCollection([
				new QueryItemVO({label:"男",extend:"0x00ff00",id:"1"}),
				new QueryItemVO({label:"女",extend:"0x00ff00",id:"1"}),
				new QueryItemVO({label:"中性",extend:"0x00ff00",id:"1"}),
				new QueryItemVO({label:"儿童",extend:"0x00ff00",id:"1"}),
			]);
			var arr:Array = [];
			for( var i:int = 0 ; i < pageSize ; i++ )
			{
				var item:ProductItemVO = new ProductItemVO();
				if( i == 0 && currentPage < 2 )
				{
					item.isRecommend = true;
				}
				item.productId = pageSize + ":" + i;
				item.price = 12345;
				item.v1pinPrice = 11246;
				item.name = ( currentPage + ":"  + i ) + "【2012春夏新款】Dolce&Gabbana深棕色带" ;
				item.mainPic = picList[ Math.floor(Math.random() * 6)];
				item.picList = ["http://i0.ihaveu.net.cn/image/auction/product/004/010/631/major_pic/d60f0391.jpg.thumb145.jpg",
					"http://i2.ihaveu.net.cn/image/auction/product/000/400/011/major_pic/f1ccf240.jpg.thumb145.jpg",
					"http://i1.ihaveu.net.cn/image/auction/product/000/400/441/major_pic/14d9576b.jpg.thumb145.jpg",
					"http://i2.ihaveu.net.cn/image/auction/product/000/400/011/major_pic/f1ccf240.jpg.thumb145.jpg",
					"http://i1.ihaveu.net.cn/image/auction/product/000/400/441/major_pic/14d9576b.jpg.thumb145.jpg",
					"http://i2.ihaveu.net.cn/image/auction/product/000/400/011/major_pic/f1ccf240.jpg.thumb145.jpg",
					"http://i1.ihaveu.net.cn/image/auction/product/000/400/441/major_pic/14d9576b.jpg.thumb145.jpg",
					"http://i3.ihaveu.net.cn/image/auction/product/004/010/853/major_pic/3124c6bd.jpg.thumb145.jpg",
					"http://i3.ihaveu.net.cn/image/auction/product/003/999/324/major_pic/76a13acb.jpg.thumb145.jpg"];
				arr.push( item );
			}
			listVO.list = new ArrayCollection(arr);
			listVO.brandInfo = new BrandInfoVO({cname:"古奇",ename:"Gucci",title:"【2012春夏新款】Dolce&Gabbana深棕色带",createTime:"2008年",cradle:"法国",
				keyword:"啊啊啊，斑斑驳驳，尺寸",describe:"【2012春夏新款】Dolce&Gabbana深棕色带【2012春夏新款】Dolce&Gabbana深棕色带【2012春夏新款】Dolce&Gabbana深棕色带【" +
					"2012春夏新款】Dolce&Gabbana深棕色带【2012春夏新款】Dolce&Gabbana深棕色带【2012春夏新款】Dolce&Gabbana深棕色带【2012春夏新款】Dolce&Gabbana深棕色带【2012" +
					"春夏新款】Dolce&Gabbana深棕色带【2012春夏新款】Dolce&Gabbana深棕色带【2012春夏新款】Dolce&Gabbana深棕色带【2012春夏新款】Dolce&Gabbana深棕色带【2012春夏新款】Dolce&Gabbana深棕色带"});
			setTimeout( resultHandler , 150 , listVO );
		}
	}
}